package com.kakavr.result;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import com.kakavr.util.ConvertUtils;

/**
 * 返回结果工具
 * 
 * @author gang.yang
 */
public class Result extends MsgResult {
	/**
	 * 输出json结果
	 * 
	 * @method outJson
	 * @param result
	 *            要输出的json字符串
	 * @param response
	 *            response对象
	 * @return void
	 */
	public static void outJson(String result, HttpServletResponse response) {
		PrintWriter pw = null;
		try {
			response.setCharacterEncoding("UTF-8");
			response.setContentType("application/json");
			pw = response.getWriter();
			pw.write(result);
			pw.flush();
		} catch (IOException e) {
			
		} finally {
			if (pw != null) {
				pw.close();
			}
		}
	}

	/**
	 * 输出字符串
	 * 
	 * @method outText
	 * @param result
	 *            要输出的文本
	 * @param response
	 *            response对象
	 * @return void
	 */
	public static void outText(String result, HttpServletResponse response) {
		PrintWriter pw = null;
		try {
			response.setCharacterEncoding("UTF-8");
			response.setContentType("text/plain");
			pw = response.getWriter();
			pw.write(result);
			pw.flush();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (pw != null) {
				pw.close();
			}
		}
	}
	
	public static void outJson(Map<String, Object> msgResult,HttpServletResponse response){
		outJson(ConvertUtils.toJson(msgResult), response);
	}

}
